package app.project.directionlensproject.util;

public class AppUtils {
	public static float DistancePlace(double latlatitudeA, double longitudeA, double latlatitudeB, double longitudeB) {
		double lat1 = latlatitudeA;
		double lon1 = longitudeA;
		double lat2 = latlatitudeB;
		double lon2 = longitudeB;

		final int r = 6371; // km
		double dLat = ToRadian(lat2 - lat1);
		double dLon = ToRadian(lon2 - lon1);
		double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(ToRadian(lat1)) * Math.cos(ToRadian(lat2))
				* Math.sin(dLon / 2) * Math.sin(dLon / 2);
		double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
		double d = r * c;
		
		return (float)Math.round(d * 100) / 100;
	}

	private static double ToRadian(double val) {
		return ((Math.PI / 180) * val);
	}
}
